<?php
/**
 * Created by PhpStorm.
 * User: zhixuedong
 * Date: 2021/9/7
 * Time: 14:45
 */

namespace app\api\controller;
use think\Config;
use think\Controller;
use think\Db;
use think\Exception;
use think\Session;
use think\Validate;

class Help extends Controller
{
    public function iflogin(){
        $project_user = Session::get("project_user");
        if(empty($project_user)){
            $black['code'] = 1;
            $black['msg'] = "请重新登录";
            echo json_encode($black);die;
        }
        return $project_user;
    }

    //所有求助信息
    public function helpAll(){
        $common = new Common();
        if(!empty($_POST['uid'])){
            $project_user = $common->testusername($_POST['uid']);
        }else{
            $project_user = $this->iflogin();
        }

        try{
            $page = empty($_POST['page'])?1:$_POST['page'];
            $limit = empty($_POST['limit'])?10:$_POST['limit'];
            $start = ($page-1)*$limit;

            //获取已读信息
            $logWhere['read_id'] = $project_user['id'];
            $logId = Db::name("project_help_log")->where($logWhere)->field("help_id")->select();  //已读消息
            $logId = array_column($logId,"help_id");

            $where['pid'] = 0;

            if(!empty($_POST['status'])){
                $where['status'] = $_POST['status'];
            }

            if(!empty($_POST['keyword'])){
                $proWhere['title'] = ["like","%{$_POST['keyword']}%"];
                $proList = Db::name("project_pro")->where($proWhere)->field("id")->select();
                $proList = array_column($proList,"id");
                $where['pro_id'] = ['in',$proList];
            }

            if(!empty($_POST['publicWarehousingCode'])){
                $publicWarehousingCode = $_POST['publicWarehousingCode'];
                switch ($publicWarehousingCode){
                    case 1:
                        $where['status'] = 3;
                        break;
                    case 2:
                        $where['sumbit_time'] = ['like',"%".date("Y-m")."%"];
                        break;
                    case 3:
                        $where['status'] = 3;
                        $where['sumbit_time'] = ['like',"%".date("Y-m")."%"];
                        break;
                }
            }

//            $where['accountId'] = ['like',"%,{$project_user['id']},%"];

            //获取未读信息
            $readWhere['id'] = ['not in',$logId];
//            $readWhere['accountId'] = ['like',"%,{$project_user['id']},%"];
//            $readWhere['sumbit_id'] = ['neq',$project_user['id']];
            $readList = Db::name("project_help")->where($readWhere)->field("id,pid")->select();  //未读信息
            $readCount = count($readList);
            //获取未读信息end
            $readId1 = array_unique(array_column($readList,'id'));
            $readId2 = array_unique(array_column($readList,'pid'));
            $readId = array_unique(array_merge($readId1,$readId2));

            $list = Db::name("project_help")->where($where)->limit($start,$limit)->order("id desc")->select();
            $count = Db::name("project_help")->where($where)->count("*");

            foreach ($list as $k=>$v){
                if(in_array($v['id'],$readId)){
                    $readStatus = 1;
                }else{
                    $readStatus = 0;
                }
                $list[$k]['readStatus'] = $readStatus;
                $readWhere['pid'] = $v['id'];
                $Unread = Db::name("project_help")->where($readWhere)->count("*");
                if($Unread==0 && $readStatus==1){
                    $Unread++;
                }
                $list[$k]['Unread'] = $Unread;

                //查询项目名称
                $proName = '';
                $proWhere['id'] = $v['pro_id'];
                $proName = Db::name("project_pro")->where($proWhere)->value("title");
                $list[$k]['proName'] = $proName;

                //查询提交人
                $sumbitName = '';
                $accountWhere['id'] = $v['sumbit_id'];
                $sumbitName = Db::name("project_account")->where($accountWhere)->value("name");
                $list[$k]['sumbitName'] = $sumbitName;

                //查询协调人员信息
                $accountId = explode(",",$v['accountId']);
                $accountId = array_filter($accountId);
                $accountWhere1['id'] = ['in',$accountId];
                $coordinateList = $common->public_select("project_account",$accountWhere1,"id,name,dictionariesId")->select();
                $list[$k]['coordinate'] = $coordinateList;

                $list[$k]['addtime'] = date("Y-m-d H:i:s",$v['addtime']);
            }


            $black['code'] = 0;
            $black['list'] = $list;
            $black['count'] = $count;
            $black['readCount'] = $readCount;
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);

    }



    //查询责任单位
    public function dictionaries(){
        try{
            $appid = $_POST['appid'];
            $config = Db::name("config")->where(['xcx_appid' => $appid])->find();
            $where['uniacid'] = $config['id'];
            $where['status'] = 1;
            //搜索责任单位
            if(!empty($_POST['keyword'])){
                $where['name'] = ['like',"%{$_POST['keyword']}%"];
            }
            $list = Db::name("project_dictionaries")->where($where)->field("id,name")->select();

            $black['code'] = 0;
            $black['list'] = $list;
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }

    //查询责任单位下面的人员
    public function personnel(){
        try{
            $project_user = $this->iflogin();
            $appid = $_POST['appid'];
            $config = Db::name("config")->where(['xcx_appid' => $appid])->find();
            $where['uniacid'] = $config['id'];
            if(!empty($_POST['dictionariesId'])){
                $where['dictionariesId'] = $_POST['dictionariesId'];
            }else{
                $where['dictionariesId'] = ['gt',0];
            }
            $where['status'] = 1;
            //搜索人员
            if(!empty($_POST['keyword'])){
                $where['name'] = ['like',"%{$_POST['keyword']}%"];
            }
            $where['id'] = ['neq',$project_user['id']];
            $list = Db::name("project_account")->where($where)->field("id,name")->select();
            $black['code'] = 0;
            $black['list'] = $list;
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }

    public function personnelDetail(){
        try{
            $where['id'] = $_POST['id'];
            $detail = Db::name("project_account")->where($where)->find();

            //查询部门信息
            unset($where);
            $where['id'] = $detail['dictionariesId'];
            $dictionaries = Db::name("project_dictionaries")->where($where)->value("name");

            $returnBlack['name'] = $detail['name'];
            $returnBlack['id'] = $detail['id'];
            $returnBlack['selDictionariesName'] = $dictionaries;

            $black['code'] = 0;
            $black['detail'] = $returnBlack;
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }



    //发送短信
    public function publicSms($phone,$code,$smsData){
        $sina = "湖北东土太一智慧科技";
        sms($phone, $sina, $code, $smsData);
    }

    //提交求助信息
    public function createHelp(){
        $common = new Common();
        if(!empty($_POST['uid'])){
            $project_user = $common->testusername($_POST['uid']);
        }else{
            $project_user = $this->iflogin();
        }
        try{
            $appid = $_POST['appid'];
            $config = Db::name("config")->where(['xcx_appid' => $appid])->find();


            if(empty($_POST['pro_id'])){
                throw new Exception("请选择项目");
            }

            if(empty($_POST['phone'])){
                throw new Exception("请输入联系电话");
            }
            if(!isPoneLandline($_POST['phone'])){
                throw new Exception("手机号码格式有误");
            }

            if(empty($_POST['content'])){
                throw new Exception("请填写求助内容");
            }

            $accountList = json_decode($_POST['accountId'],true);
            if(count($accountList)==0){
                throw new Exception("请选择协助人员");
            }
            $accountId = "";
            foreach ($accountList as $k=>$v){
                $accountId .= ','.$v['personnelId'];
            }
            $data['phone'] = $_POST['phone'];
            $data['uniacid'] = $config['id'];
            $data['sumbit_id'] =$project_user['id'];
            $data['pro_id'] = $_POST['pro_id'];
            $data['sumbit_time'] = $_POST['sumbit_time'];
            $data['content'] = $_POST['content'];
            $data['accountId'] = $accountId.",";
            $data['addtime'] = time();
            Db::name("project_help")->insert($data);

            //发送短信操作(需要加短信功能)(新功能)
            $title = mb_substr($project_user['name'],0,14,'utf-8');
            $smsData['username'] = "【{$title}…】";
            $smsData = json_encode($smsData,JSON_UNESCAPED_UNICODE);
            $code = "SMS_240361237";
            foreach ($accountList as $item){
                $accountWhere['name'] = $item['personnelName'];
                $accountPhone = Db::name("project_account")->where($accountWhere)->value("phone");
                if(!empty($accountPhone)){
                    $this->publicSms($accountPhone,$code,$smsData);
                }
            }

            $black['code'] = 0;
            $black['msg'] = "操作成功";
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }

    //回复求助信息
    public function replyHelp(){
        $common = new Common();
        if(!empty($_POST['uid'])){
            $project_user = $common->testusername($_POST['uid']);
        }else{
            $project_user = $this->iflogin();
        }
        try{
            $appid = $_POST['appid'];
            $config = Db::name("config")->where(['xcx_appid' => $appid])->find();
            $data['uniacid'] = $config['id'];

            //查询求助信息
            $id = $_POST['id'];
            $where['id'] = $id;
            $detail = Db::name("project_help")->where($where)->find();

            $replyCount = Db::name("project_help")->where(['pid'=>$id])->count("*");

            //判断办结时间是否超过15天
            $netTime = time();
            if(!empty($_POST['finish_time'])){
                $date=floor(($netTime-strtotime($_POST['finish_time']))/86400);
                $date = abs($date);
                if($date>15){
                    throw new Exception("办结日期不能超过当前时间的15天");
                }
                $update['finish_time'] = $_POST['finish_time'];
            }

            if($replyCount==0 & empty($_POST['finish_time'])){
                throw new Exception("办结日期不能为空");
            }

            //更改求助信息状态
            $update['status'] = $detail['status'];
            if($detail['status']<2){
                $update['status'] = 2;
            }

            if($detail['sumbit_id'] == $project_user['id']){
                if(empty($_POST['evaluate'])){
                    throw new Exception("请选择评价");
                }
            }

            if(!empty($_POST['evaluate'])){
                $newTime = date("Y-m-d");
                $update['evaluate'] = $evaluate = $_POST['evaluate'];

                if($evaluate==1){
                    $update['status'] = 3;
//                    if($newTime>$detail['finish_time']){
//                        $update['status'] = 7;
//                    }
                }

            }
            Db::name("project_help")->where($where)->update($update);
            if(empty($_POST['content'])){
                throw new Exception("请输入回复内容");
            }

            if(!empty($_POST['type']) & $_POST['type']==2){
                if(empty($_POST['person'])){
                    throw new Exception("请输入责任人");
                }
                if(empty($_POST['contact'])){
                    throw new Exception("请输入联系电话");
                }
                $data['person'] = $_POST['person'];
                $data['contact'] = $_POST['contact'];
            }

            $data['pid'] = $detail['id'];
            $data['sumbit_id'] =$project_user['id'];
            $data['pro_id'] = $detail['pro_id'];
//            $data['sumbit_time'] = $_POST['sumbit_time'];
            $data['content'] = $_POST['content'];
//            $data['dictionariesId'] = $_POST['dictionariesId'];
            $data['accountId'] = empty($_POST['accountId'])?$detail['accountId']:$_POST['accountId'];
            $data['finish_time'] = $_POST['finish_time'];
            $data['addtime'] = time();


            Db::name("project_help")->insert($data);

            if($replyCount==0){
                //发送短信操作(需要加短信功能)(新功能)
                $title = mb_substr($project_user['name'],0,14,'utf-8');
                $smsData['username'] = "【{$title}…】";
                $smsData = json_encode($smsData,JSON_UNESCAPED_UNICODE);
                $code = "SMS_240361241";
                $accountWhere['id'] = $detail['sumbit_id'];
                $accountPhone = Db::name("project_account")->where($accountWhere)->value("phone");
                if(!empty($accountPhone)){
                    $this->publicSms($accountPhone,$code,$smsData);
                }
            }
            $black['code'] = 0;
            $black['msg'] = "操作成功";
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }




    //查看求助信息
    public function helpDetail(){
        $common = new Common();
        if(!empty($_POST['uid'])){
            $project_user = $common->testusername($_POST['uid']);
        }else{
            $project_user = $this->iflogin();
        }
        try{
            $id = $_POST['id'];
            $where['id'] = $id;
            $detail = Db::name("project_help")->where($where)->find();

            $detail['addtime'] = date("Y-m-d H:i:s",$detail['addtime']);

            $evaluate = [1=>"满意",2=>"不满意"];
            $detail['evaluate'] = empty($evaluate[$detail['evaluate']])?"":$evaluate[$detail['evaluate']];

            //查询项目
            $detail['project'] = "";
            if(!empty($detail['pro_id'])){
                $proWhere['id'] = $detail['pro_id'];
                $detail['project'] = $common->public_select("project_pro",$proWhere)->value("title");
            }

            //查询协调人员信息
            $accountId = explode(",",$detail['accountId']);
            $accountId = array_filter($accountId);
            $accountWhere['id'] = ['in',$accountId];
            $coordinateList = $common->public_select("project_account",$accountWhere,"id,name,dictionariesId")->select();
            foreach ($coordinateList as $k=>$v){
                //查询责任单位
                $dictionariesWhere['id'] = $v['dictionariesId'];
                $dictionaries = $common->public_select("project_dictionaries",$dictionariesWhere)->value("name");
                $coordinateList[$k]['dictionaries'] = empty($dictionaries)?"":$dictionaries;
            }
            $detail['coordinateList'] = $coordinateList;
            //查询协调人员信息end

            $status = [
                1=>"待回复",2=>"办理中",3=>"已办结",4=>"已评价",5=>"已关闭",6=>"已逾期",7=>"逾期办结"
            ];
            $detail['statusName'] = $status[$detail['status']];

            //查询提交人
            $accountWhere1['id'] = $detail['sumbit_id'];
            $detail['sumbit_name'] = $common->public_select("project_account",$accountWhere1)->value("name");


            $logWhere['help_id'] = $logData['help_id'] = $detail['id'];
            $logWhere['read_id'] = $logData['read_id'] =  $project_user['id'];
            $logData['addtime'] = time();

            //记录查看日志
            $logId = Db::name("project_help_log")->where($logWhere)->value("id");
            if(empty($logId)){
                Db::name("project_help_log")->insert($logData);
            }else{
                $logData['id'] = $logId;
                Db::name("project_help_log")->update($logData);
                unset( $logData['id']);
            }

            //查询回复信息
            $helpWhere['pid'] = $id;
            $reply = Db::name("project_help")->where($helpWhere)->order("id desc")->select();
            //查询提交人信息
            foreach ($reply as $k=>$v){
                $reply[$k]['addtime'] = date("Y-m-d H:i:s",$v['addtime']);
                $accountWhere['id'] = $v['sumbit_id'];
                $account = Db::name("project_account")->where($accountWhere)->find();
                $reply[$k]['accountName'] = $account['name'];
                //记录查看日志
                $logWhere['help_id'] = $logData['help_id'] = $v['id'];
                $logId = Db::name("project_help_log")->where($logWhere)->value("id");
                if(empty($logId)){
                    Db::name("project_help_log")->insert($logData);
                }else{
                    $logData['id'] = $logId;
                    Db::name("project_help_log")->update($logData);
                    unset( $logData['id']);
                }
            }

            $replyCount = Db::name("project_help")->where(['pid'=>$id])->count("*");
            $detail['finish_time'] = empty($replyCount)?"":$detail['finish_time'];

            $black['code'] = 0;
            $black['detail'] = $detail;
            $black['reply'] = $reply;
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }

    //统计求助信息
    public function helpStatistics(){
        $common = new Common();
        if(!empty($_POST['uid'])){
            $project_user = $common->testusername($_POST['uid']);
        }else{
            $project_user = $this->iflogin();
        }

        try{
            $where['pid'] = 0;
            $type = empty($_POST['type'])?1:$_POST['type'];
            switch ($type){
                case 1:
                    $where['sumbit_id'] = $project_user['id'];
                    break;
                case 2:
                    $where['accountId'] = ['like',"%,{$project_user['id']},%"];
                    break;
                case 20:
                    $where['type'] = 1;
                    $where['accountId'] = ['like',"%,{$project_user['id']},%"];
                    break;
            }

            $stateArray = [1,2];
            foreach ($stateArray as $k=>$v){
                if($v==1){
                    $where['status'] = $v;
                }else{
                    $where['status'] = ['not in',[3,4,5]];
                }

                $stateArray[$k] = Db::name("project_help")->where($where)->count("*");
            }
            $black['code'] = 0;
            $black['stateArray'] = $stateArray;
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }




    //求助列表
    public function helpList(){
        $common = new Common();
        $nowtime = time();
        if(!empty($_POST['uid'])){
            $project_user = $common->testusername($_POST['uid']);
        }else{
            $project_user = $this->iflogin();
        }
        try{
            $page = empty($_POST['page'])?1:$_POST['page'];
            $limit = empty($_POST['limit'])?10:$_POST['limit'];
            $start = ($page-1)*$limit;

            $readCount = 0;

            //获取已读信息
            $logWhere['read_id'] = $project_user['id'];
            $logId = Db::name("project_help_log")->where($logWhere)->field("help_id")->select();  //已读消息
            $logId = array_column($logId,"help_id");

            $where['pid'] = 0;
            $type = empty($_POST['type'])?1:$_POST['type'];

            if(!empty($_POST['status'])){
                $where['status'] = $_POST['status'];
            }

            if(!empty($_POST['keyword'])){
                $proWhere['title'] = ["like","%{$_POST['keyword']}%"];
                $proList = Db::name("project_pro")->where($proWhere)->field("id")->select();
                $proList = array_column($proList,"id");
                $where['pro_id'] = ['in',$proList];
            }

            if(!empty($_POST['score'])){
               switch ($_POST['score']){
                   case 5:
                       $where['score'] = 5;
                       break;
                   case 3:
                       $where['score'][] = ['egt',3];
                       $where['score'][] = ['lt',5];
                       break;
                   case 1:
                       $where['score'][] = ['egt',1];
                       $where['score'][] = ['lt',3];
                       break;
               }
            }

            if(!empty($_POST['state'])){
                switch ($_POST['state']){
                    case 1:
                        $where['status'] = 1;
                        break;
                    case 2:
                        $where['status'] = ['not in',[3,4,5]];
                        break;
                }
            }

            if($type==1){
                $where['sumbit_id'] = $project_user['id'];
                //获取未读信息
                $ids = Db::name("project_help")->where($where)->field("id")->select();  //我的求助信息
                $ids = array_column($ids,"id");
                $ids = array_unique(array_merge($ids,$logId));
                $readWhere['id'] = ['not in',$ids];
                $readWhere['pid'] = ['in',$ids];
                $readList = Db::name("project_help")->where($readWhere)->field("id,pid")->select();  //未读信息
                $readCount = count($readList);
                //获取未读信息end
                $readId = array_unique(array_column($readList,'pid'));
            }elseif ($type==3){
                $where['status'] = 6;
                //获取未读信息
                $ids = Db::name("project_help")->where($where)->field("id")->select();  //我的求助信息
                $ids = array_column($ids,"id");
                $ids = array_unique(array_merge($ids,$logId));
                $readWhere['id'] = ['not in',$ids];
                $readWhere['pid'] = ['in',$ids];
                $readList = Db::name("project_help")->where($readWhere)->field("id,pid")->select();  //未读信息
                $readCount = count($readList);
                //获取未读信息end
                $readId = array_unique(array_column($readList,'pid'));

            }elseif ($type==20){
                $where['type'] = 1;
                $where['accountId'] = ['like',"%,{$project_user['id']},%"];
                //获取未读信息
                $ids = Db::name("project_help")->where($where)->field("id")->select();  //我的求助信息
                $ids = array_column($ids,"id");
                $ids = array_unique(array_merge($ids,$logId));
                $readWhere['id'] = ['not in',$ids];
                $readWhere['pid'] = ['in',$ids];
                $readList = Db::name("project_help")->where($readWhere)->field("id,pid")->select();  //未读信息
                $readCount = count($readList);
                //获取未读信息end
                $readId = array_unique(array_column($readList,'pid'));
            }else{
                $where['accountId'] = ['like',"%,{$project_user['id']},%"];
                //获取未读信息
                $readWhere['id'] = ['not in',$logId];
                $readWhere['accountId'] = ['like',"%,{$project_user['id']},%"];
                $readWhere['sumbit_id'] = ['neq',$project_user['id']];
                $readList = Db::name("project_help")->where($readWhere)->field("id,pid")->select();  //未读信息
                $readCount = count($readList);
                //获取未读信息end
                $readId1 = array_unique(array_column($readList,'id'));
                $readId2 = array_unique(array_column($readList,'pid'));
                $readId = array_unique(array_merge($readId1,$readId2));
            }

            $list = Db::name("project_help")->where($where)->limit($start,$limit)->order("id desc")->select();
            $count = Db::name("project_help")->where($where)->count("*");

            $evaluate = [1=>"满意",2=>"不满意"];


            foreach ($list as $k=>$v){
                $list[$k]['evaluate'] = empty($evaluate[$v['evaluate']])?"":$evaluate[$v['evaluate']];

                if(in_array($v['id'],$readId)){
                    $readStatus = 1;
                }else{
                    $readStatus = 0;
                }
                $list[$k]['readStatus'] = $readStatus;
                $readWhere['pid'] = $v['id'];
                $Unread = Db::name("project_help")->where($readWhere)->count("*");
                if($Unread==0 && $readStatus==1){
                    $Unread++;
                }
                $list[$k]['Unread'] = $Unread;

                //查询项目名称
                $proWhere['id'] = $v['pro_id'];
                $proName = Db::name("project_pro")->where($proWhere)->value("title");
                $list[$k]['proName'] = empty($proName)?"":$proName;

                //查询提交人
                $sumbitName = '';
                $accountWhere['id'] = $v['sumbit_id'];
                $sumbitName = Db::name("project_account")->where($accountWhere)->value("name");
                $list[$k]['sumbitName'] = $sumbitName;

                //查询协调人员信息
                $accountId = explode(",",$v['accountId']);
                $accountId = array_filter($accountId);
                $accountWhere1['id'] = ['in',$accountId];
                $coordinateList = $common->public_select("project_account",$accountWhere1,"id,name,dictionariesId")->select();
                $list[$k]['coordinate'] = $coordinateList;
                $list[$k]['addtime'] = date("Y-m-d H:i:s",$v['addtime']);

            }


            $black['code'] = 0;
            $black['list'] = $list;
            $black['count'] = $count;
            $black['readCount'] = $readCount;
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }


    //评价操作
    public function scoreApi(){
        $common = new Common();
        if(!empty($_POST['uid'])){
            $project_user = $common->testusername($_POST['uid']);
        }else{
            $project_user = $this->iflogin();
        }
        try{
            $id = $_POST['id'];
            $where['id'] = $id;
            $detail = Db::name("project_help")->where($where)->find();

            if(empty($_POST['content'])){
                throw new Exception("请输入评价内容");
            }

            $data['score_contetn'] = $_POST['content'];
            $data['score'] = empty($_POST['score'])?1:$_POST['score'];
            $data['status'] = 3;
            Db::name("project_help")->where($where)->update($data);
            $black['code'] = 0;
            $black['msg'] = "操作成功";
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }

    //查询评价内容
    public function scoreDetailApi(){
        $common = new Common();
        if(!empty($_POST['uid'])){
            $project_user = $common->testusername($_POST['uid']);
        }else{
            $project_user = $this->iflogin();
        }
        try{
            $id = $_POST['id'];
            $where['id'] = $id;
            $detail = Db::name("project_help")->where($where)->find();

            $black['code'] = 0;
            $black['detail'] = $detail;
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return json_encode($black);
    }
}